Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding approach for Bob #2861

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Conversation

jagdish-15
Copy link
Contributor

pull request

This pull request adds an approach to the Bob exercise.

I was unsure how to generate a uuid for the approach, so I've left it empty. I would greatly appreciate guidance on how to generate one.


Reviewer Resources:

Track Policies

if (isAsking(inputTrimmed))
return "Sure.";

return "Whatever.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I think this approach is the same as the existing if-statement approach. The only difference is that the conditions are in methods instead of variables. Is there something else that differentiates this approach from the other ones?

Copy link
Contributor Author

@jagdish-15 jagdish-15 Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kahgoh for your feedback! I understand your point, and while both the method-based approach and the if statement approach use condition checks, there are a few key differences that I think set the method-based approach apart:

  1. Separation of Concerns:

    • In the method-based approach, I’ve separated the logic for determining if the message is a question, shouting, or silent into individual methods (isYelling(), isAsking(), isSilent()). This makes the main hey() method cleaner and focused on handling the flow of responses.
    • In the if approach, the logic is directly embedded in the main method, which could become harder to read and maintain as more checks are added.
  2. Improved Readability:

    • With the helper methods, it’s clear what each condition is doing without having to dive into complex inline if statements. For example, isYelling() immediately tells you that it’s checking for shouting behaviour, and isAsking() clarifies the question check.
    • This helps future readers (and even future maintainers) quickly grasp the purpose of each check.
  3. Maintainability:

    • While maintainability may not be a major concern for these one-time exercises, the method-based approach provides a structure that makes it easier to modify individual checks without cluttering the main method. This is generally a good practice for ensuring clean, readable, and maintainable code, even in simple exercises.
  4. Scalability:

    • While this specific exercise may not need to scale in the future, separating the logic into individual methods makes it much easier to extend or modify if more conditions are added down the line. Even though we don’t expect more checks here, structuring code this way is generally a good practice for scalability in larger, more complex applications.

In summary, while both approaches work, the method-based approach tends to be cleaner, more modular, and easier to extend. It may seem similar on the surface, but the structure I’ve chosen is designed with maintainability and scalability in mind, which are good practices even for small exercises like this one.

If you have any suggestions or further insights on this approach, I'd be happy to hear them!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it has taken me quite a while to get back to this one. I think I can see where you are coming from. Looking around, I noticed Python's approach has two similar if approaches for Bob (if statements and if statements nested). If we were to proceed this approach, perhaps we could do something similar by naming the approach in a similar way to the if statements (for example, if statements with checks in methods).

Btw, looking at the points mentioned under General guidance, there is a point about determining the yelling and questioning once: Use variables for questioning and shouting rather than calling these checks multiple times to improve efficiency. In your example solution, you calling the method again, so it is going to be recalculated. But, my worry about putting them in variables is that it will look even closer to the current if statements approach.

I think the way you've currently is fine as it is, but may be worth pointing out this short coming in the introduction's Which approach to use? .

@jagdish-15
Copy link
Contributor Author

I've updated this approach to incorporate all the suggestions from the PR for the Queen Attack exercise here. This update ensures consistency in style with the other exercises' approaches. Additionally, the newly added approach's content.md file is now aligned with the format and structure of the two existing approaches.

Please review and let me know your thoughts on this version.

@jagdish-15 jagdish-15 closed this Nov 26, 2024
@jagdish-15 jagdish-15 deleted the add-approach-bob branch November 26, 2024 17:42
@jagdish-15 jagdish-15 restored the add-approach-bob branch November 26, 2024 17:56
@jagdish-15 jagdish-15 reopened this Nov 26, 2024
if (isAsking(inputTrimmed))
return "Sure.";

return "Whatever.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it has taken me quite a while to get back to this one. I think I can see where you are coming from. Looking around, I noticed Python's approach has two similar if approaches for Bob (if statements and if statements nested). If we were to proceed this approach, perhaps we could do something similar by naming the approach in a similar way to the if statements (for example, if statements with checks in methods).

Btw, looking at the points mentioned under General guidance, there is a point about determining the yelling and questioning once: Use variables for questioning and shouting rather than calling these checks multiple times to improve efficiency. In your example solution, you calling the method again, so it is going to be recalculated. But, my worry about putting them in variables is that it will look even closer to the current if statements approach.

I think the way you've currently is fine as it is, but may be worth pointing out this short coming in the introduction's Which approach to use? .

return "Whatever.";
}

private boolean isYelling(String input) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the intro and other approaches for this exercise, we have used the term "shouting" instead of "yelling". I'd suggest using the same terminology to keep it consistent within the approaches.

.allMatch(Character::isUpperCase);
}

private boolean isAsking(String input) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, we've used the term "questioning" in the intro and other approaches.


## General guidance
## General Guidance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the casing in the headings need changing - there are consistent with most other other approaches. Could you undo the changes to the headings?

exercises/practice/bob/.approaches/method-based/content.md Outdated Show resolved Hide resolved
exercises/practice/bob/.approaches/introduction.md Outdated Show resolved Hide resolved
@jagdish-15
Copy link
Contributor Author

Hello @kahgoh,

My apologies for the delay in responding. I have revised the files to incorporate all of the suggested changes. Please review them at your convenience and let me know if any further improvements are necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants